package com.ld.security.server.blog.modules.cms.service.impl;

import com.ld.security.common.mybatis.base.po.PagePo;
import com.ld.security.common.mybatis.base.service.ISuperServiceImpl;
import com.ld.security.common.mybatis.base.vo.PageVo;
import com.ld.security.common.mybatis.util.JdbcUtil;
import com.ld.security.server.blog.modules.cms.constant.CmsCollectUserRelConstant;
import com.ld.security.server.blog.modules.cms.entity.CmsCollectEntity;
import com.ld.security.server.blog.modules.cms.entity.CmsCollectUserRelEntity;
import com.ld.security.server.blog.modules.cms.mapping.CmsCollectMapping;
import com.ld.security.server.blog.modules.cms.service.ICmsCollectService;
import com.ld.security.server.blog.modules.cms.service.ICmsCollectUserRelService;
import com.ld.security.server.blog.modules.cms.vo.AuthCollectionVo;
import com.ld.security.server.blog.modules.cms.vo.CollectDetailsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CmsCollectServiceImpl  extends ISuperServiceImpl<CmsCollectEntity>
implements
        ICmsCollectService {

        @Autowired
        ICmsCollectUserRelService iCmsCollectUserRelService;
        @Autowired
        CmsCollectMapping cmsCollectMapping;

        @Override
        public PageVo<AuthCollectionVo> getAuthCollection(PagePo<AuthCollectionVo> po) {
                return  JdbcUtil.page(po);

        }

        /**
         * 添加合集权限
         * @param entity
         */
        @Override
        protected void saveAfter(CmsCollectEntity entity,boolean iner){
                if(iner){
                        CmsCollectUserRelEntity e =  iCmsCollectUserRelService.newInstance();
                        e.setCollectId(entity.getId());
                        e.setUserId(entity.getAuthorId());
                        e.setRelType(CmsCollectUserRelConstant.relType.master);
                        iCmsCollectUserRelService.save(e);
                }
        }


        @Override
        public CollectDetailsVo getDetails(String id) {
                CollectDetailsVo vo = new CollectDetailsVo();
                vo.setId(id);
                this.proxyQuery(vo);

                cmsCollectMapping.incrTotal(id);

                return vo;
        }
}
